//package com.wushi.lenovo.asia5b.app_ui.other.dialog.trans;
//
//import android.content.Context;
//import android.content.DialogInterface;
//import android.content.Intent;
//import android.support.v7.app.AlertDialog;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.text.TextUtils;
//import android.view.Gravity;
//import android.view.View;
//import android.widget.Button;
//import android.widget.ImageView;
//import android.widget.LinearLayout;
//import android.widget.TextView;
//
//import com.mvp.base.BaseAppCompatActivity;
//import com.mvp.base.BaseDialog;
//import com.mvp.base.model.ResultModel;
//import com.mvp.dagger.modules.NetworkModule;
//import com.mvp.utils.DecimalUtil;
//import com.mvp.utils.StringUtils;
//import com.mvp.utils.ToastUtil;
//import com.wushi.lenovo.asia5b.R;
//import com.wushi.lenovo.asia5b.app_config.BaseEvents;
//import com.wushi.lenovo.asia5b.app_http.ApiService;
//import com.wushi.lenovo.asia5b.app_http.TopupService;
//import com.wushi.lenovo.asia5b.app_model.credit.EmailModel;
//import com.wushi.lenovo.asia5b.app_model.credit.MemberBlanceModel;
//import com.wushi.lenovo.asia5b.app_model.credit.bean.ChangeCreditType;
//import com.wushi.lenovo.asia5b.app_model.credit.bean.TopupInfoBean;
//import com.wushi.lenovo.asia5b.app_model.other.TransItemBean;
//import com.wushi.lenovo.asia5b.app_model.other.UserInfo;
//import com.wushi.lenovo.asia5b.app_ui.other.dialog.ForgotPayPassDialog;
//import com.wushi.lenovo.asia5b.app_ui.profile.activity.FirstPayPassActivity;
//import com.wushi.lenovo.asia5b.app_utils.helper.CrashHelper;
//import com.wushi.lenovo.asia5b.app_widget.pass.PayPwdEditText;
//
//import org.greenrobot.eventbus.EventBus;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//
//import butterknife.BindView;
//import butterknife.OnClick;
//import io.reactivex.Observable;
//import io.reactivex.ObservableSource;
//import io.reactivex.android.schedulers.AndroidSchedulers;
//import io.reactivex.disposables.CompositeDisposable;
//import io.reactivex.disposables.Disposable;
//import io.reactivex.functions.Function;
//import io.reactivex.schedulers.Schedulers;
//
//import static timber.log.Timber.d;
//
///**
// * Created by zhangyuncai on 2019/1/16.
// */
//public class TransferDialog extends BaseDialog {
//
//    @BindView(R.id.tv_ctransfer_confirm)
//    TextView tv_ctransfer_confirm;//
//    @BindView(R.id.tv_ctransfer_1)
//    TextView tv_ctransfer_1;
//    @BindView(R.id.paypwd_ctarnsfer)
//    PayPwdEditText paypwd_ctarnsfer;//密码
//    @BindView(R.id.bt_ctransfer_submit)
//    Button bt_ctransfer_submit;//提交
//    @BindView(R.id.tv_ctrans_pass_error)
//    TextView tv_ctrans_pass_error;
//    @BindView(R.id.ll_trans_notice_vessel)
//    LinearLayout ll_trans_notice_vessel;
//    @BindView(R.id.iv_trans_noticeicon)
//    ImageView iv_trans_noticeicon;
//    @BindView(R.id.tv_trans_notice)
//    TextView tv_trans_notice;
//    @BindView(R.id.rv_transfer)
//    RecyclerView mRecyclerView;
//    TransAdapter mAdapter;
//    private final List<TransItemBean> mDatas = new ArrayList<>();
//    private final ApiService apiService = NetworkModule.getRetrofit().create(ApiService.class);
//    private final TopupService topupService = NetworkModule.getRetrofit().create(TopupService.class);
//    private final ChangeCreditType changeCreditType;
//    private Map<String, Object> map;
//    private final BaseAppCompatActivity activity;
//    private CompositeDisposable composite;
//
//    public TransferDialog(Context context, ChangeCreditType changeCreditType) {
//        super(context);
//        this.changeCreditType = changeCreditType;
//        activity = (BaseAppCompatActivity) context;
//        this.composite = new CompositeDisposable();
//    }
//
//
//    @Override
//    protected int getLayoutId() {
//        return R.layout.dialog_transfer;
//    }
//
//    @Override
//    protected void initView() {
//        setCanceledOnTouchOutside(false);
//        paypwd_ctarnsfer.initStyle(R.drawable.edit_num_bg, 6, 0.33f, R.color.common_text_black, R.color.common_text_black, 20);
//        mAdapter = new TransAdapter(mDatas);
//        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
//        mRecyclerView.setAdapter(mAdapter);
//    }
//
//    public void setMap(Map<String, Object> map) {
//        this.map = map;
//    }
//
//    public void setViewForTransfer(MemberBlanceModel memberBlanceModel, EmailModel emailModel, String transAcount) {
//        mDatas.clear();
//        mDatas.add(new TransItemBean(getString(R.string.c_transfer_receiver), emailModel.getName()));//姓名
//        mDatas.add(new TransItemBean(getString(R.string.c_transfer_email), emailModel.getEmail()));//邮箱
//        mDatas.add(new TransItemBean(getString(R.string.c_transfer_creditbalance), memberBlanceModel.getBalance_value()));//账户金额
//        mDatas.add(new TransItemBean(getString(R.string.c_transfer_transferamount), StringUtils.formatNum2(transAcount)));//转账金额
//        String totalBalance = DecimalUtil.subtract(memberBlanceModel.getBalance_value(), transAcount);
//        d("--->>>>>>>>---totalBalance:" + totalBalance);
//        mDatas.add(new TransItemBean(getString(R.string.c_transfer_totalbalance), StringUtils.formatNum2(totalBalance)));//转账后余额
//        mAdapter.notifyDataSetChanged();
//    }
//
//    public void setViewForPaySuff(TopupInfoBean topupInfoBean) {
//        mDatas.clear();
//        mDatas.add(new TransItemBean(getString(R.string.c_transfer_creditbalance), topupInfoBean.getBalance_value()));//账户金额
//        mDatas.add(new TransItemBean(getString(R.string.withdraw_totalamount), topupInfoBean.getTotalAmount()));//转账金额
//        String totalBalance = DecimalUtil.subtract(topupInfoBean.getBalance_value(), topupInfoBean.getTotalAmount());
//        mDatas.add(new TransItemBean(getString(R.string.c_transfer_totalbalance), StringUtils.formatNum2(totalBalance)));//转账后余额
//        mAdapter.notifyDataSetChanged();
//    }
//
//    public void setViewForWithdraw(Map<String, Object> map, MemberBlanceModel memberBlanceModel, String account) {
//        mDatas.clear();
//        mDatas.add(new TransItemBean(getString(R.string.withdraw_recipientbank), map.get("holeded_bank").toString()));//账户金额
//        mDatas.add(new TransItemBean(getString(R.string.withdraw_accountnumber), map.get("bank_acc_no").toString()));//账户金额
//        mDatas.add(new TransItemBean(getString(R.string.withdraw_recipientname), map.get("account_holder_name").toString()));//账户金额
//        mDatas.add(new TransItemBean(getString(R.string.withdraw_creditbalance), memberBlanceModel.getBalance_value()));//账户金额
//        mDatas.add(new TransItemBean(getString(R.string.withdraw_withdrawamount), account + ""));//账户金额
//        String totalBalance = DecimalUtil.subtract(memberBlanceModel.getBalance_value(), account);
//        mDatas.add(new TransItemBean(getString(R.string.withdraw_totalbalance), StringUtils.formatNum2(totalBalance)));//账户金额
//        mAdapter.notifyDataSetChanged();
//    }
//
//
//    private boolean isCanRequest = true;//是否可以请求接口,防止用户双击等操作
//
//    private void checkPayPass(String payPass) {
//        if (map == null) {
//            CrashHelper.postCatchedException(new Throwable("map is error!"));
//            return;
//        }
//        if (!isCanRequest) {
//            return;
//        }
//        isCanRequest = false;
//        Disposable subscribe = apiService.checkPayPass(UserInfo.getMemberId(), payPass)
//                .flatMap(new Function<ResultModel, ObservableSource<ResultModel>>() {
//                    @Override
//                    public ObservableSource<ResultModel> apply(ResultModel resultModel) throws Exception {
//                        if (resultModel.isSuccess()) {
//                            return pay(payPass);
//                        } else {
//                            resultModel.setResult(2);
//                        }
//                        return Observable.just(resultModel);
//                    }
//                })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .doOnSubscribe(disposable -> {
//                    if (activity != null) {
//                        activity.showLoadingBar(null);
//                    }
//                })
//                .doAfterTerminate(() -> {
//                    if (activity != null) {
//                        activity.dismissLoadingBar("");
//                    }
//                })
//                .subscribe(resultModel -> {
//                    isCanRequest = true;
//                    if (callBack != null) {
//                        callBack.callback(resultModel);
//                    }
//                    BaseEvents.OrderPayEvent creditChangeEvent = new BaseEvents.OrderPayEvent(changeCreditType, resultModel.isSuccess() ? 1 : 0);
//                    EventBus.getDefault().post(creditChangeEvent);
//                    if (isShowing()) {
//                        if (!resultModel.isSuccess()) {
//                            paypwd_ctarnsfer.clearText();
//                        }
//                        if (resultModel.getResult() == 2) {
//                            tv_ctrans_pass_error.setVisibility(View.VISIBLE);
//                            ToastUtil.showToast(resultModel.getMsg());
//                        } else {
//                            transSuccess(resultModel.isSuccess());
//                            if (!resultModel.isSuccess()) {
//                                ToastUtil.showToast(resultModel.getMsg());
//                            }
//                        }
//
//                    }
//                }, throwable -> {
//                    throwable.printStackTrace();
//                    isCanRequest = true;
//                });
//        composite.add(subscribe);
//    }
//
//    private Observable<ResultModel> pay(String payPass) {
//        if (changeCreditType == ChangeCreditType.credit_withdraw) {
//            map.put("payment_password", payPass);
//            return apiService.getSubmitWithdrawData(map);
//        } else if (changeCreditType == ChangeCreditType.credit_transfer) {
//            map.put("payment_password", "" + payPass);
//            return apiService.getUsernameTransferAccount(map);
//        } else if (changeCreditType == ChangeCreditType.orderpayment_sufficient) {//PaySufficient
//            map.put("topup_password", "" + payPass);
//            return topupService.submitTopupForPayment(map);
//        }
//        return null;
//    }
//
//    @Override
//    protected void initListener() {
//        paypwd_ctarnsfer.setOnTextChangeListener(content -> {
//            tv_ctrans_pass_error.setVisibility(View.INVISIBLE);
//        });
//    }
//
//    @OnClick({
//            R.id.bt_ctransfer_submit,
//            R.id.tv_ctransfer_forgot,
//            R.id.tv_tag_close
//    })
//    @Override
//    public void onClick(View v) {
//        switch (v.getId()) {
//            case R.id.bt_ctransfer_submit://提交
//                Object tag = bt_ctransfer_submit.getTag();
//                if (tag != null && TextUtils.equals(tag.toString(), "ok")) {
//                    dismiss();
//                    return;
//                }
//                if (!UserInfo.getUserInfo().getHas_pay_pass()) {
//
//                    new AlertDialog.Builder(getContext())
//                            .setTitle(R.string.not_paypss)
//                            .setNegativeButton(R.string.cancel, null)
//                            .setPositiveButton(R.string.set_paypss, new OnClickListener() {
//                                @Override
//                                public void onClick(DialogInterface dialog, int which) {
//                                    activity.startActivity(new Intent(activity, FirstPayPassActivity.class));
//                                }
//                            })
//                            .create().show();
//                    return;
//                }
//                String pwdText = paypwd_ctarnsfer.getPwdText();
//                if (!TextUtils.isEmpty(pwdText) && pwdText.length() == 6) {
////                    callback.callback(pwdText);
//                    checkPayPass(pwdText);
//                } else {
////                    ToastUtil.showToast("error!");
//                }
//                break;
//            case R.id.tv_ctransfer_forgot://忘记密码
//                if (activity != null) {
//                    if (UserInfo.getUserInfo().getHas_pay_pass()) {
//                        ForgotPayPassDialog forgotPayPassDialog = new ForgotPayPassDialog(activity);
//                        forgotPayPassDialog.show();
//                    } else {
//                        activity.startActivity(new Intent(activity, FirstPayPassActivity.class));
//                    }
//                }
//                break;
//            case R.id.tv_tag_close://关闭
//                dismiss();
//                break;
//            default:
//                break;
//        }
//    }
//
//
//    private void transSuccess(boolean isSuccess) {
//        ll_trans_notice_vessel.setVisibility(View.VISIBLE);
//        bt_ctransfer_submit.setText(R.string.ok);
//        bt_ctransfer_submit.setTag("ok");
//        int successText = 0;
//        int errorText = 0;
//        if (changeCreditType == ChangeCreditType.credit_transfer) {
//            successText = R.string.c_transfer_transfersuccessful;
//            errorText = R.string.c_transfer_transferfailed;
//        } else {
//            successText = R.string.paymentsuccessful;
//            errorText = R.string.paymentfailed;
//        }
//        if (isSuccess) {
//            iv_trans_noticeicon.setImageResource(R.drawable.icon_trans_right);
//            tv_trans_notice.setText(successText);
//        } else {
//            iv_trans_noticeicon.setImageResource(R.drawable.icon_trans_error);
//            tv_trans_notice.setText(errorText);
//        }
//    }
//
//
//    @Override
//    protected int getGravity() {
//        return Gravity.CENTER;
//    }
//
//    @Override
//    protected int getWidthStyle() {
//        return getScreenWidth(0.9f);
//    }
//
//    @Override
//    public void dismiss() {
//        if (composite != null && !composite.isDisposed()) {
//            composite.dispose();
//        }
//        super.dismiss();
//    }
//
//}
